<?php
class Trigger_Page
{
	static public function onAfterDelete(Db_Object $object)
	{
		if(!Application::getDataCache())
			return;
			
		self::clearBlockCache($object->getId());
		self::clearItemCache($object->code ,$object->getId());	
	}
	
	static public function onAfterAdd(Db_Object $object)
	{
		self::clearBlockCache($object->getId());
	}
	
	static public function onAfterUpdate(Db_Object $object)
	{
		if(!Application::getDataCache())
			return;
			
		self::clearBlockCache($object->getId());
		self::clearItemCache($object->code ,$object->getId());	
	}
	
	static public function clearItemCache($code , $id)
	{
		$cache = Application::getDataCache();
		if($cache){
			$cache->remove(Model_Page::getCodeHash($code));
			$cache->remove(Model_Page::getCodeHash($id));
			$cache->remove(Frontend_Router::CACHE_KEY_ROUTES);
		}
	}
	
	static public function clearBlockCache($pageId)
	{
		$cache = Application::getDataCache();
		if($cache){
			$cache->remove(Block_Menu::CACHE_KEY);	
			$cache->remove(Blockmanager::hashPage($pageId));
		}
	}
}